/**
 * @filaname dept
 * @description 选择部门
 * @author  Rocky
 * @date    2019-10-26 12:09
 * @email   jintaozhao@qq.com
 * @version 1.0.0
 */

/**
 * 选择部门树
 */
function selectDeptTree() {
    var deptId = $("#deptId").val() ? $("#deptId").val() : 1;
    var options = {
        title: '部门选择',
        width: "380",
        url: ctx + "system/dept/selectDeptTree/" + deptId,
        callBack: doSubmit
    };
    $.modal.openOptions(options);
}

function doSubmit(index, layero) {
    var body = layer.getChildFrame('body', index);
    var deptId = body.find('#treeId').val();
    // var result = checkDeptHasChildren(deptId);
    // if (result == '0') {
        $("#deptId").val(body.find('#treeId').val());
        $("#deptName").val(body.find('#treeName').val());
        layer.close(index);
    // } else {
    //     $.modal.alertError("所选部门不是一级部门，请重新选择");
    // }
}

function checkDeptHasChildren(deptId) {
    var result;
    $.ajax({
        url: ctx + "system/dept/checkDeptHasChildren/" + deptId,
        type: "post",
        dataType: "json",
        contentType: false,
        async: false,
        success: function (value) {
            result = value;
        }
    });
    return result;
}